﻿using QYmall.Core.IServices;
using Quartz;

namespace QYmall.Core.API.Quartz
{
    /// <summary>
    /// 订单定时任务(防并发)
    /// </summary>
    [DisallowConcurrentExecution]
    public class OrderCancelJobs : IJob
    {
        private readonly ILogger<OrderCancelJobs> _logger;
        private readonly IOrderCollectionService _orderCollectionService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        public OrderCancelJobs(ILogger<OrderCancelJobs> logger, IOrderCollectionService orderCollectionService)
        {
            _logger = logger;
            _orderCollectionService = orderCollectionService;
        }

        /// <summary>
        /// 执行任务
        /// </summary>
        public async Task Execute(IJobExecutionContext context)
        {
            //_logger.LogInformation($"订单定时任务开始：{DateTime.Now}");
            await _orderCollectionService.JobCancelAsync();
            /*await Task.Run(() =>
            {
                _logger.LogInformation("订单定时任务开始：" + DateTime.Now);
            });*/
        }
    }
}
